﻿Imports System.IO

Public Class FileActions
    Function FindProcess(ext As String) As String
        Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot
        Dim secondKey As String
        Dim rtn As String = ""

        If Not ext.StartsWith(".") Then
            ext = "." & ext
        End If

        key = key.OpenSubKey(ext)

        If key IsNot Nothing Then
            secondKey = key.GetValue("").ToString()

            If secondKey <> "" Then
                key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(secondKey & "ShellOpenCommand")
                rtn = key.GetValue("").ToString()
                rtn = System.Text.RegularExpressions.Regex.Match(rtn, """(.*?)""").Groups(0).Value
            End If
        End If

        Return rtn
    End Function
    Shared Function DeleteFile(Filename As String) As SAEventArgs
        If File.Exists(Filename) = True Then
            Try
                Dim objFile As New FileInfo(Filename) With {.Attributes = FileAttributes.Normal}
                objFile.Delete()
                objFile = Nothing

                Return New SAEventArgs("", SAEventArgs.Results.Success)
            Catch ex As Exception
                Return New SAEventArgs(ex.Message, SAEventArgs.Results.GeneralFailure)
            End Try
        Else
            Return New SAEventArgs(Filename & " does not exists", SAEventArgs.Results.FileMissing)
        End If
    End Function
End Class
